#include "dialog.h"
#include "ui_dialog.h"
#include "execsql.h"
#include <QMessageBox>
#include <QCryptographicHash>
#include <qdebug.h>
#include <stdio.h>
#include <stdlib.h>
QString testerAccount;      // 声明一个全局变量用于窗体间传值

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::on_pb_cancel_clicked()
{
    this->close();
}

void Dialog::on_pb_login_clicked()
{
    QString username = ui->le_account->text();
    QString password =ui->le_password->text();
    QString salt = "90e5f54713b57975";
    QString combined = password + salt;
    QString md5_Password = QCryptographicHash::hash(combined.toLatin1(),QCryptographicHash::Md5).toHex();
    qDebug() << "加密密码：" << md5_Password;
//    printf("%s\n",md5_Password.toLatin1());
    if(ExecSQL::findUser(username,md5_Password))
    {
        qDebug() << "加密密码：" << md5_Password;
//        printf("%s\n",md5_Password.toLatin1());
        testerAccount = ui->le_account->text();
        accept();
    }
    else
    {
        QMessageBox::warning(this,tr("警告!"),tr("密码错误或网络连接失败,请重试!"),QMessageBox::Yes);
    }
}
